package com.sogeti.mentormatch.control
{
	import com.adobe.cairngorm.control.FrontController;
	import com.sogeti.mentormatch.command.*;
	import com.sogeti.mentormatch.event.*;

	/**
	 * The MentorMatchController class is the class that handles the pairing or matching of 
	 * Cairngorm events to Cairngorm commands. Using the addCommand() method allows you to setup these
	 * pairings.
	 * 
	 * Using just one sub method in the constructor, we use initialize commands. If we had alot more
	 * events -> and commands, then we could break it down into further dissection. Like a Initialize 
	 * authentication commands, mentor commands, sub page commands etc. 
	 */
	public class MentorMatchController extends FrontController
	{
		/**
		 * The constructor 
		 */
		public function MentorMatchController()
		{
			intializeCommands();
		}
		
		/**
		 * the initializeCommands() method is simply where we organize all our events, and command patterns.
		 * Remember that events dispatched with the CairngormEventDispatcher.dispatch() method, or the
		 * event.dispatch() method on CairngormEvents both go directly here to the controller. 
		 * 
		 * This allows for a lack of 'bubbling' to occur. Basically we dont have to allow the events to bubble
		 * up. They simply go right here. 
		 * 
		 * We use the addCommand(event.STATIC_EVENT_VAR_TYPE, commandClass) syntax to match up events and thier
		 * types to specific commands. 
		 * 
		 * Lets say we had an authenticate event with 2 types:
		 * 1: AuthenticateEvent.LOGIN_EVENT
		 * 2: AuthenticateEvent.LOGOUT_EVENT
		 * 
		 * We would want to pair these to different commands, because though the event can be generic, the 
		 * command CANNOT be. So we would add the two different types of events using the same method, but 
		 * with a different signature like so:
		 * 
		 * addCommand(Authenticate.LOGIN_EVENT, LoginCommand);
		 * addCommand(Authenticate.LOGOUT_EVENT, LogoutCommand);
		 * 
		 * Obviously the LoginCommand and the LogoutCommand are going to do different things. In this way
		 * we have direct pairing of events to commands.
		 */
		private function intializeCommands() : void
		{
			addCommand(LoginEvent.EVENT_LOGIN, LoginCommand);
			addCommand(LogoutEvent.LOGOUT_EVENT, LogoutCommand);
		}
		
	}
}